/*
 * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.mrd.gtimpframe.service.impl;

import com.mrd.gtimpframe.entity.GenProtocolProp;
import com.mrd.gtimpframe.repository.GenProtocolPropMapper;
import com.mrd.gtimpframe.service.DictionaryService;
import com.mrd.gtimpframe.service.ProtocolPropService;
import com.mrd.util.LoginUtil;
import com.mrd.util.StringUtils;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.transaction.Transactional;

/**
 * Created by dengdc on 2017/8/3.
 */
@Service
public class ProtocolPropServiceImpl implements ProtocolPropService {
	@Resource
	private GenProtocolPropMapper	genProtocolPropMapper;
	@Resource
	private DictionaryService		dictionaryService;

	/**
	 * 批量更新或修改
	 */
	@Override
	@Transactional
	public void batchSaveOrUpdate(List<GenProtocolProp> props) {
		Set<String> protocolIds = new HashSet<>();
		for(GenProtocolProp prop : props) {
			protocolIds.add(prop.getProtocolId());
			prop.setId(StringUtils.getUUID());
			prop.setCreator(LoginUtil.getLoginAccount());
			prop.setCreateTime(new Date());
		}
		List<String> protocolIdList = new ArrayList<>(protocolIds);
		genProtocolPropMapper.batchDeleteByProtocolIds(protocolIdList);
		genProtocolPropMapper.batchInsertSelective(props);
	}

	@Override
	public List<GenProtocolProp> selectByProtocolIds(List<String> protocolIds) {
		return genProtocolPropMapper.selectByProtocolIds(protocolIds);
	}

    @Override
    public List<GenProtocolProp> selectByProtocolIdsAndDtGroupType(List<String> protocolIds,
            String dtGroupType) {
        return null;
    }

}
